﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using PrinterBudi.Persistence;

namespace PrinterBudi.Web.Controllers
{
    public class LoginController : Controller
    {
        //
        // GET: /Login/
        [HttpPost]
        public ActionResult Index(String username, String password)
        {
            RedirectResult rr = null;
            PBUser logUser = PBUserModel.Read(username);
            if (logUser.Password.Equals(password))
            {
                if (logUser.VerSuccess == 0)
                {
                    rr = Redirect("/Home/Login?retry=2");
                }
                else
                {
                    Session["userId"] = logUser.Id;
                    rr = Redirect("/Home");
                }
            }
            else
            {
                ViewBag.User= username;
                rr = Redirect("/Home/Login?retry=1");
            }
            return rr;
        }

    }
}
